package au.edu.qut.bpm.genbinder.genetic.genesis;

import java.util.Random;
import au.edu.qut.bpm.genbinder.models.Activity;
import au.edu.qut.bpm.genbinder.models.Case;
import au.edu.qut.bpm.genbinder.models.ConcreteEventLog;

public class LogSequentialScheduleFactory extends LogAbstractFactory {
	
	public LogSequentialScheduleFactory(ConcreteEventLog log) {
		super(log);
	}

	@Override
	public ConcreteEventLog generateRandomCandidate() {
		ConcreteEventLog newLog = new ConcreteEventLog(templateLog);
		long placeAfter = 0;
		
		for (Case c : newLog.getAbstractLog().getCases()) {
			boolean first = true;
			if (first)
				if (c.getArrival() >= placeAfter)
					placeAfter = c.getArrival();
			first = false;
			
			for (Activity a : c.getOrderedTrace()) {
				newLog.setActivityStart(a, placeAfter);
				newLog.setActivityResources(a, a.getResource());
				
				placeAfter = newLog.getActivityEnd(a);
			}
		}
		return newLog;
	}
	
	@Override
	public ConcreteEventLog generateRandomCandidate(Random rng) {
		return generateRandomCandidate();
	}
	
	@Override
	public ConcreteEventLog generateRandomCandidate(boolean performSafetyCheck, Random rng) {
		return generateRandomCandidate(rng);
	}
}
